// Copyright 2013 The golog2bq Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package log2bq

import (
	"bytes"
	"compress/gzip"
	"io"
)

const bqDataType = "application/octet-stream"

type logData struct {
	g io.WriteCloser
	b io.ReadWriter
}

func newLogData() *logData {
	buff := &bytes.Buffer{}
	return &logData{
		g: gzip.NewWriter(buff),
		b: buff,
	}
}

func (d *logData) Read(p []byte) (n int, err error) {
	return d.b.Read(p)
}

func (d *logData) ContentType() string {
	return bqDataType
}

func (d *logData) Write(p []byte) (n int, err error) {
	return d.g.Write(p)
}

func (d *logData) doneWriting() error {
	return d.g.Close()
}
